package com.fingard.dsp.bank.directbank.cmbc01;

import com.fingard.FGBiz;
import com.fingard.constant.Format;
import com.fingard.db.JDBCHelper;
import com.fingard.dsp.bank.dbobj.receipt.ReceiptData;
import com.fingard.dsp.bank.dbobj.receipt.ReceiptDataHelper;
import com.fingard.dsp.bank.directConfig.ReceiptProConfig;
import com.fingard.dsp.bank.directbank.bankInterface.IReceiptPro;
import com.fingard.dsp.bank.reqrespobj.downloadreceipt.ReqQryReceipt;
import com.fingard.dsp.bank.reqrespobj.downloadreceipt.RetAtsReceipt;
import com.fingard.dsp.task.command.SyncReceipt;
import com.fingard.io.FileHelper;
import com.fingard.text.StringHelper;
import com.fingard.util.DateHelper;
import com.fingard.util.secret.salary.FieldHiddenUtil;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;
import org.springframework.stereotype.Component;

import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by F on 2020/1/19.
 */
@Component("CMBC01ReceiptPro")
public class CMBC01ReceiptPro extends CMBC01Base implements IReceiptPro {
    @Override
    public RetAtsReceipt qryReceiptOneDay(ReceiptProConfig pConfig, ReqQryReceipt pReqReceipt, Date pOneDay) throws Exception {

        //当1.1接口异常或1.1接口查询到最后一页时跳出循环
        String qryDay = Format.Date10Format.format(pOneDay);
        ReceiptDataHelper receiptHelper = null;//回单数据保存类，分区分表
        try {
            receiptHelper = new ReceiptDataHelper(pReqReceipt.reqHeader.tenant, pOneDay);
            //ATSES-26613民生银行新增当日电子回单查询接口
            if (DateHelper.isSameDay(pOneDay, new Date())) {
                //查询今日回单信息
                qryTodayReceiptInfo(receiptHelper, pReqReceipt, qryDay);
            } else {
                //查询回单信息
                qryReceiptInfo(receiptHelper, pReqReceipt, qryDay);
            }

            String aLog = "";
            //下载文件
            aLog = pReqReceipt.actNum + "," + qryDay + "回单数据查询完成，开始下载文件";
            WriteBankLogLn(aLog);
            FGBiz.logTrace.info(this.getLogCode(), aLog);
            ArrayList<String> list = receiptHelper.getIstNbrList(pReqReceipt.actNum, pOneDay);
            aLog = pReqReceipt.actNum + "," + qryDay + "需要进行下载的回单文件个数：" + list.size();
            WriteBankLogLn(aLog);
            FGBiz.logTrace.info(this.getLogCode(), aLog);
            if (list.size() <= 0) {
                return null;
            }
            //开始下载文件
            for (int i = 0; i < list.size(); i++) {
                //ATSES-26613民生银行新增当日电子回单查询接口
                if (DateHelper.isSameDay(pOneDay, new Date())) {
                    todayPdfDownLoad(receiptHelper, pConfig, pReqReceipt, list.get(i));
                } else {
                    pdfDownLoad(receiptHelper, pConfig, pReqReceipt, list.get(i));
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            WriteBankLogLn(ex.getMessage());
            FGBiz.logTrace.error(this.getLogCode(), ex.getMessage());
        } finally {
            receiptHelper.close();
        }
        SyncReceipt.resetDelayCounter();//同步任务重新计数延时
        return null;
    }

    private void todayPdfDownLoad(ReceiptDataHelper receiptHelper, ReceiptProConfig pConfig, ReqQryReceipt pReqReceipt, String istNbr) {
        String aLog = "";
        try {
            synchronized (CMBC01ReceiptPro.class) {
                if (getBankConfig().getValueAsString("waitSecsEachReqForReceipt").length() > 0) {
                    long sleepTime = Long.parseLong(getBankConfig().getValueAsString("waitSecsEachReqForReceipt")) * 1000;
                    Thread.sleep(sleepTime);
                } else {
                    Thread.sleep(5000L);
                }
                ReceiptData receiptData = receiptHelper.loadFromDbByIstNbr(pReqReceipt.actNum, istNbr);
                Date tranDate = Format.Date8Format.parse(receiptData.busDate + "");

                XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
                //写入通用的头部节点
                CMBC01Header bankHeader = new CMBC01Header();
                bankHeader.trnCode = "ElectNoteDownLoad";
                writeCommonHeader(xmlWriter, bankHeader);
                xmlWriter.writeStartElement("xDataBody");
                xmlWriter.writeElementString("trnId", getQryTransID());
                xmlWriter.writeElementString("AcNo", pReqReceipt.actNum);
                xmlWriter.writeElementString("innerNo", receiptData.istNbr);
                xmlWriter.writeElementString("FileName", receiptData.busRef3);
                xmlWriter.writeEndDocument();
                FGBiz.logTrace.info(this.getLogCode(), "发送银行的报文");
                FGBiz.logTrace.info(this.getLogCode(), xmlWriter.toXmlString());
                String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
                FGBiz.logTrace.info(this.getLogCode(), "银行返回的报文");
                FGBiz.logTrace.info(this.getLogCode(), FieldHiddenUtil.wordHiddle(tmpStrRet[1], new String[]{"DownloadFileContent"}));
                XmlTextReader tmpBkReader;

                if (tmpStrRet[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                    if (tmpBkReader != null) {
                        String tmpRetCode = tmpBkReader.getFirstText("/CMBC/responseHeader/status/code");
                        String tmpRetMessage = tmpBkReader.getFirstText("/CMBC/responseHeader/status/message");
                        if (tmpRetCode.equals("0")) {
                            String fileContent = tmpBkReader.getFirstText("/CMBC/xDataBody/FileContent");
                            String FileName = tmpBkReader.getFirstText("/CMBC/xDataBody/FileName");

                            String localPath = pConfig.getRelativeSaveDir(pReqReceipt.reqHeader, tranDate) + File.separator + pReqReceipt.actNum;
                            localPath += File.separator + Format.Date10Format.format(tranDate);

                            String localFileRelative = localPath + File.separator + StringHelper.trimStartFileSp(FileName);
                            localFileRelative = StringHelper.replaceFileSp(localFileRelative);
                            String localPdfFilePath = pConfig.localSaveMainDir + File.separator + localFileRelative;

                            if (!FileHelper.existFile(localPdfFilePath)) {
                                FileHelper.writeBytesToFile(localPdfFilePath, new sun.misc.BASE64Decoder().decodeBuffer(fileContent));
                            }
                            if (FileHelper.existFile(localPdfFilePath)) {
                                int rowAff = receiptHelper.updateDownState(pReqReceipt.actNum, receiptData.istNbr, localFileRelative, FileName, "2");
                                aLog = "回单编号" + receiptData.istNbr + "，文件" + FileName + "下载成功，更新影响行数：" + rowAff;
                                aLog = aLog + "\r\n文件保存地址：" + localPdfFilePath;
                                WriteBankLogLn(aLog);
                                FGBiz.logTrace.info(this.getLogCode(), aLog);
                            } else {
                                aLog = "回单编号" + receiptData.istNbr + "，文件" + FileName + "下载失败";
                                WriteBankLogLn(aLog);
                                FGBiz.logTrace.error(this.getLogCode(), aLog);
                            }
                        } else {
                            aLog = "回单编号：" + receiptData.istNbr + "对于的回单文件下载失败：" + tmpRetMessage;
                            WriteBankLogLn(aLog);
                            FGBiz.logTrace.error(this.getLogCode(), aLog);
                        }
                    } else {
                        aLog = "回单编号：" + receiptData.istNbr + "对于的回单文件下载失败：" + tmpSbMsg.toString();
                        WriteBankLogLn(aLog);
                        FGBiz.logTrace.error(this.getLogCode(), aLog);
                    }
                } else {
                    aLog = "回单编号：" + receiptData.istNbr + "对于的回单文件下载失败：" + tmpStrRet[1];
                    WriteBankLogLn(aLog);
                    FGBiz.logTrace.error(this.getLogCode(), aLog);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            WriteBankLogLn(ex.getMessage());
            FGBiz.logTrace.error(this.getLogCode(), ex.getMessage());
        }
    }

    private void qryTodayReceiptInfo(ReceiptDataHelper receiptHelper, ReqQryReceipt pReqReceipt, String qryDateStr) {
        int tmpAllNum = -1;//总条数
        int tmpReadedNum = 0;//已读取数
        int tmpEachReqLen = 50;//每次请求条数
        int tmpStartNO = 0;//请求页码

        String aLog;
        try {
            do {//分页查询
                tmpStartNO++;
                XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
                //写入通用的头部节点
                CMBC01Header bankHeader = new CMBC01Header();
                bankHeader.trnCode = "QryElectNoteList";
                writeCommonHeader(xmlWriter, bankHeader);
                xmlWriter.writeStartElement("xDataBody");
                xmlWriter.writeElementString("trnId", getQryTransID());
                xmlWriter.writeElementString("AcNo", pReqReceipt.actNum);
                xmlWriter.writeElementString("MinMoney", "");
                xmlWriter.writeElementString("MaxMoney", "");
                xmlWriter.writeElementString("pageNo", String.valueOf(tmpStartNO));
                xmlWriter.writeElementString("pageSize", String.valueOf(tmpEachReqLen));
                xmlWriter.writeEndDocument();
                FGBiz.logTrace.info(this.getLogCode(), "开始查询今日回单");
                FGBiz.logTrace.info(this.getLogCode(), "发送银行的报文");
                FGBiz.logTrace.info(this.getLogCode(), xmlWriter.toXmlString());
                String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
                FGBiz.logTrace.info(this.getLogCode(), "银行返回的报文");
                FGBiz.logTrace.info(this.getLogCode(), tmpStrRet[1]);
                XmlTextReader tmpBkReader;
                int tmpPageRdNum = 0;
                if (tmpStrRet[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                    if (tmpBkReader != null) {
                        String tmpRetCode = tmpBkReader.getFirstText("/CMBC/responseHeader/status/code");
                        String tmpRetMessage = tmpBkReader.getFirstText("/CMBC/responseHeader/status/message");
                        if (tmpRetCode.equals("0")) {
                            //总记录数
                            if (tmpAllNum == -1) {
                                tmpAllNum = Integer.parseInt(tmpBkReader.getFirstText("/CMBC/xDataBody/Count"));
                            }
                            if (tmpAllNum <= 0) {
                                WriteBankLogLn("查无回单");
                                FGBiz.logTrace.info(this.getLogCode(), "查无回单");
                                break;
                            }
                            while (tmpBkReader.read("/CMBC/xDataBody/List/Map")) {
                                tmpPageRdNum++;
                                tmpReadedNum++;
                                ReceiptData rcpt = new ReceiptData();
                                rcpt.bank = "305";
                                rcpt.srcSys = this.bankFront.bankCode;
                                rcpt.istNbr = tmpBkReader.readedXElement.getSingleText("innerNo");//回单编号
                                rcpt.receiptNo = rcpt.istNbr;
                                rcpt.bnkSeqNo = tmpBkReader.readedXElement.getSingleText("svrId");
                                String TRAN_DATE = tmpBkReader.readedXElement.getSingleText("TrsDate");//交易日期
                                rcpt.busDate = Integer.parseInt(DateHelper.convertD10toD8(TRAN_DATE));

                                if (!qryDateStr.equals(TRAN_DATE)) {
                                    aLog = rcpt.receiptNo + "回单数据的日期" + TRAN_DATE + "与预期" + qryDateStr + "不符";
                                    WriteBankLogLn(aLog);
                                    FGBiz.logTrace.error(this.getLogCode(), aLog);
                                }
//                                rcpt.oppActNum = tmpBkReader.readedXElement.getSingleText("AcNo");
//                                rcpt.oppActName = tmpBkReader.readedXElement.getSingleText("BillName");
                                rcpt.cur = convertCurToATS(tmpBkReader.readedXElement.getSingleText("Currency"));
                                rcpt.busRef3 = tmpBkReader.readedXElement.getSingleText("FileName");
                                String loanFlag = tmpBkReader.readedXElement.getSingleTextNotNull("LoanFlag");
                                if ("0".equals(loanFlag)) {
                                    loanFlag = "1";
                                } else if ("1".equals(loanFlag)) {
                                    loanFlag = "2";
                                } else {
                                    aLog = rcpt.receiptNo + "回单数据的收支标志不符合要求" + loanFlag + "与预期不符";
                                    WriteBankLogLn(aLog);
                                    FGBiz.logTrace.error(this.getLogCode(), aLog);
                                }
                                rcpt.moneyWay = loanFlag;

                                rcpt.amount = new BigDecimal(tmpBkReader.readedXElement.getSingleText("TrsAmount"));
                                rcpt.ownAct = pReqReceipt.actNum;
                                int inRe = receiptHelper.insertIfNotExist(rcpt);
                                if (inRe == 0) {
                                    aLog = "回单编号:" + rcpt.istNbr + "写入数据库，影响行数：" + inRe;
                                    WriteBankLogLn(aLog);
                                    FGBiz.logTrace.error(this.getLogCode(), aLog);
                                } else if (inRe == 1) {
                                    aLog = "回单编号:" + rcpt.istNbr + "更新数据库，影响行数：" + inRe;
                                    WriteBankLogLn(aLog);
                                    FGBiz.logTrace.error(this.getLogCode(), aLog);
                                }
                            }
                        } else {
                            WriteBankLogLn(tmpRetMessage);
                            FGBiz.logTrace.error(this.getLogCode(), tmpRetMessage);
                            break;
                        }
                    } else {
                        WriteBankLogLn(tmpSbMsg.toString());
                        FGBiz.logTrace.error(this.getLogCode(), tmpSbMsg.toString());
                        break;
                    }
                } else {
                    WriteBankLogLn(tmpStrRet[1]);
                    FGBiz.logTrace.error(this.getLogCode(), tmpStrRet[1]);
                    break;
                }
                if (tmpPageRdNum == 0) {
                    break;
                }
            } while (tmpReadedNum < tmpAllNum);
        } catch (Exception ex) {
            ex.printStackTrace();
            WriteBankLogLn(ex.getMessage());
            FGBiz.logTrace.error(this.getLogCode(), ex.getMessage());
        }
    }

    public void qryReceiptInfo(ReceiptDataHelper receiptHelper, ReqQryReceipt pReqReceipt, String qryDateStr) {
        int tmpAllNum = -1;//总条数
        int tmpReadedNum = 0;//已读取数
        int tmpEachReqLen = 50;//每次请求条数
        int tmpStartNO = 0;//请求页码
        String aLog;
        try {
            do {//分页查询
                tmpStartNO++;
                XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
                //写入通用的头部节点
                CMBC01Header bankHeader = new CMBC01Header();
                if ("true".equals(getBankConfig().getValueAsString("receiptQryNewFlag"))) {
                    bankHeader.trnCode = "b2eElectNoteQryNew";
                } else {
                    bankHeader.trnCode = "b2eElectNoteQry";
                }
                writeCommonHeader(xmlWriter, bankHeader);
                xmlWriter.writeStartElement("xDataBody");
                xmlWriter.writeElementString("insId", getQryTransID());
                xmlWriter.writeElementString("saAcctNo", pReqReceipt.actNum);
                xmlWriter.writeElementString("BeginDate", qryDateStr);
                xmlWriter.writeElementString("EndDate", qryDateStr);
                xmlWriter.writeElementString("PrintState", "0");
                xmlWriter.writeElementString("MinMoney", "");
                xmlWriter.writeElementString("MaxMoney", "");
                xmlWriter.writeElementString("pageNo", String.valueOf(tmpStartNO));
                xmlWriter.writeElementString("pageSize", String.valueOf(tmpEachReqLen));
                xmlWriter.writeEndDocument();
                FGBiz.logTrace.info(this.getLogCode(), "发送银行的报文");
                FGBiz.logTrace.info(this.getLogCode(), xmlWriter.toXmlString());
                String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
                FGBiz.logTrace.info(this.getLogCode(), "银行返回的报文");
                FGBiz.logTrace.info(this.getLogCode(), tmpStrRet[1]);
                XmlTextReader tmpBkReader;
                int tmpPageRdNum = 0;
                if (tmpStrRet[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                    if (tmpBkReader != null) {
                        String tmpRetCode = tmpBkReader.getFirstText("/CMBC/responseHeader/status/code");
                        String tmpRetMessage = tmpBkReader.getFirstText("/CMBC/responseHeader/status/message");
                        if (tmpRetCode.equals("0")) {
                            //总记录数
                            if (tmpAllNum == -1) {
                                tmpAllNum = Integer.parseInt(tmpBkReader.getFirstText("/CMBC/xDataBody/Count"));
                            }
                            if (tmpAllNum <= 0) {
                                WriteBankLogLn("查无回单");
                                FGBiz.logTrace.info(this.getLogCode(), "查无回单");
                                break;
                            }
                            while (tmpBkReader.read("/CMBC/xDataBody/List/Map")) {
                                tmpPageRdNum++;
                                tmpReadedNum++;
                                ReceiptData rcpt = new ReceiptData();
                                rcpt.bank = "305";
                                rcpt.srcSys = this.bankFront.bankCode;
                                rcpt.istNbr = tmpBkReader.readedXElement.getSingleText("innerNo");//回单编号
                                rcpt.receiptNo = rcpt.istNbr;
                                rcpt.bnkSeqNo = tmpBkReader.readedXElement.getSingleText("svrId");
                                String TRAN_DATE = tmpBkReader.readedXElement.getSingleText("TrsDate");//交易日期
                                rcpt.busDate = Integer.parseInt(DateHelper.convertD10toD8(TRAN_DATE));

                                if (!qryDateStr.equals(TRAN_DATE)) {
                                    aLog = rcpt.receiptNo + "回单数据的日期" + TRAN_DATE + "与预期" + qryDateStr + "不符";
                                    WriteBankLogLn(aLog);
                                    FGBiz.logTrace.error(this.getLogCode(), aLog);
                                }
//                                rcpt.oppActNum = tmpBkReader.readedXElement.getSingleText("AcNo");
//                                rcpt.oppActName = tmpBkReader.readedXElement.getSingleText("BillName");
                                rcpt.cur = convertCurToATS(tmpBkReader.readedXElement.getSingleText("Currency"));
                                rcpt.busRef3 = tmpBkReader.readedXElement.getSingleText("FileName");

                                rcpt.moneyWay = tmpBkReader.readedXElement.getSingleTextNotNull("LoanFlag");

                                rcpt.amount = new BigDecimal(tmpBkReader.readedXElement.getSingleText("TrsAmount"));
                                rcpt.ownAct = pReqReceipt.actNum;
                                int inRe = receiptHelper.insertIfNotExist(rcpt);
                                if (inRe == 0) {
                                    aLog = "回单编号:" + rcpt.istNbr + "写入数据库，影响行数：" + inRe;
                                    WriteBankLogLn(aLog);
                                    FGBiz.logTrace.error(this.getLogCode(), aLog);
                                } else if (inRe == 1) {
                                    aLog = "回单编号:" + rcpt.istNbr + "更新数据库，影响行数：" + inRe;
                                    WriteBankLogLn(aLog);
                                    FGBiz.logTrace.error(this.getLogCode(), aLog);
                                }
                            }
                        } else {
                            WriteBankLogLn(tmpRetMessage);
                            FGBiz.logTrace.error(this.getLogCode(), tmpRetMessage);
                            break;
                        }
                    } else {
                        WriteBankLogLn(tmpSbMsg.toString());
                        FGBiz.logTrace.error(this.getLogCode(), tmpSbMsg.toString());
                        break;
                    }
                } else {
                    WriteBankLogLn(tmpStrRet[1]);
                    FGBiz.logTrace.error(this.getLogCode(), tmpStrRet[1]);
                    break;
                }
                if (tmpPageRdNum == 0) {
                    break;
                }
            } while (tmpReadedNum < tmpAllNum);
        } catch (Exception ex) {
            ex.printStackTrace();
            WriteBankLogLn(ex.getMessage());
            FGBiz.logTrace.error(this.getLogCode(), ex.getMessage());
        }
    }

    public void pdfDownLoad(ReceiptDataHelper receiptHelper, ReceiptProConfig pConfig, ReqQryReceipt pReqReceipt, String istNbr) {
        String aLog = "";
        try {
            synchronized (CMBC01ReceiptPro.class) {
                if (getBankConfig().getValueAsString("waitSecsEachReqForReceipt").length() > 0) {
                    long sleepTime = Long.parseLong(getBankConfig().getValueAsString("waitSecsEachReqForReceipt")) * 1000;
                    Thread.sleep(sleepTime);
                } else {
                    Thread.sleep(5000L);
                }
                ReceiptData receiptData = receiptHelper.loadFromDbByIstNbr(pReqReceipt.actNum, istNbr);
                Date tranDate = Format.Date8Format.parse(receiptData.busDate + "");

                XmlTextWriter xmlWriter = new XmlTextWriter();//发银行报文的XML对象
                //写入通用的头部节点
                CMBC01Header bankHeader = new CMBC01Header();
                bankHeader.trnCode = "b2eElectNoteDownLoad";
                writeCommonHeader(xmlWriter, bankHeader);
                xmlWriter.writeStartElement("xDataBody");
                xmlWriter.writeElementString("insId", getQryTransID());
                xmlWriter.writeElementString("innerNo", receiptData.istNbr);
                xmlWriter.writeElementString("xmlFileName", receiptData.busRef3);
                xmlWriter.writeEndDocument();
                FGBiz.logTrace.info(this.getLogCode(), "发送银行的报文");
                FGBiz.logTrace.info(this.getLogCode(), xmlWriter.toXmlString());
                String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
                FGBiz.logTrace.info(this.getLogCode(), "银行返回的报文");
                FGBiz.logTrace.info(this.getLogCode(), FieldHiddenUtil.wordHiddle(tmpStrRet[1], new String[]{"DownloadFileContent"}));
                XmlTextReader tmpBkReader;

                if (tmpStrRet[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                    if (tmpBkReader != null) {
                        String tmpRetCode = tmpBkReader.getFirstText("/CMBC/responseHeader/status/code");
                        String tmpRetMessage = tmpBkReader.getFirstText("/CMBC/responseHeader/status/message");
                        if (tmpRetCode.equals("0")) {
                            String fileContent = tmpBkReader.getFirstText("/CMBC/xDataBody/DownloadFileContent");
                            String downloadFileName = tmpBkReader.getFirstText("/CMBC/xDataBody/DownloadFileName");

                            String localPath = pConfig.getRelativeSaveDir(pReqReceipt.reqHeader, tranDate) + File.separator + pReqReceipt.actNum;
                            localPath += File.separator + Format.Date10Format.format(tranDate);

                            String localFileRelative = localPath + File.separator + StringHelper.trimStartFileSp(downloadFileName);
                            localFileRelative = StringHelper.replaceFileSp(localFileRelative);
                            String localPdfFilePath = pConfig.localSaveMainDir + File.separator + localFileRelative;

                            if (!FileHelper.existFile(localPdfFilePath)) {
                                FileHelper.writeBytesToFile(localPdfFilePath, new sun.misc.BASE64Decoder().decodeBuffer(fileContent));
                            }
                            if (FileHelper.existFile(localPdfFilePath)) {
                                int rowAff = receiptHelper.updateDownState(pReqReceipt.actNum, receiptData.istNbr, localFileRelative, downloadFileName, "2");
                                aLog = "回单编号" + receiptData.istNbr + "，文件" + downloadFileName + "下载成功，更新影响行数：" + rowAff;
                                aLog = aLog + "\r\n文件保存地址：" + localPdfFilePath;
                                WriteBankLogLn(aLog);
                                FGBiz.logTrace.info(this.getLogCode(), aLog);
                            } else {
                                aLog = "回单编号" + receiptData.istNbr + "，文件" + downloadFileName + "下载失败";
                                WriteBankLogLn(aLog);
                                FGBiz.logTrace.error(this.getLogCode(), aLog);
                            }
                        } else {
                            aLog = "回单编号：" + receiptData.istNbr + "对于的回单文件下载失败：" + tmpRetMessage;
                            WriteBankLogLn(aLog);
                            FGBiz.logTrace.error(this.getLogCode(), aLog);
                        }
                    } else {
                        aLog = "回单编号：" + receiptData.istNbr + "对于的回单文件下载失败：" + tmpSbMsg.toString();
                        WriteBankLogLn(aLog);
                        FGBiz.logTrace.error(this.getLogCode(), aLog);
                    }
                } else {
                    aLog = "回单编号：" + receiptData.istNbr + "对于的回单文件下载失败：" + tmpStrRet[1];
                    WriteBankLogLn(aLog);
                    FGBiz.logTrace.error(this.getLogCode(), aLog);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            WriteBankLogLn(ex.getMessage());
            FGBiz.logTrace.error(this.getLogCode(), ex.getMessage());
        }
    }
}
